package com.ky.manage.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ky.manage.R;
import com.ky.manage.model.response.IndoorSecurityCheckListResp;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * 户内安检 tab adapter
 */
public class IndoorSecurityCheckTabAdapter extends BaseQuickAdapter<IndoorSecurityCheckListResp.IndoorSecurityCheckInfo, BaseViewHolder> {
    private List<IndoorSecurityCheckListResp.IndoorSecurityCheckInfo> list;
    private Context context;

    public IndoorSecurityCheckTabAdapter(Context context, int layoutId, List<IndoorSecurityCheckListResp.IndoorSecurityCheckInfo> list) {
        super(layoutId, list);
        this.list = list;
        this.context = context;
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder , IndoorSecurityCheckListResp.IndoorSecurityCheckInfo indoorSecurityCheckInfo) {
        TextView dealUserNameTv = baseViewHolder.getView(R.id.deal_user_name_tv);
        TextView badLevelTv = baseViewHolder.getView(R.id.bad_level_state_tv);
        TextView up2DoorTimeTv = baseViewHolder.getView(R.id.up_2_door_time_tv);
        TextView addressTv = baseViewHolder.getView(R.id.customer_address_tv);
        if (null == indoorSecurityCheckInfo) {
            return;
        }
        dealUserNameTv.setText(indoorSecurityCheckInfo.clientName);
        badLevelTv.setText(getBadLevelStr(indoorSecurityCheckInfo.hiddenDangerLevel));
        badLevelTv.setTextColor(getStateTxtColor(indoorSecurityCheckInfo.hiddenDangerLevel));
        up2DoorTimeTv.setText("上门时间：" + indoorSecurityCheckInfo.finishTime);
        addressTv.setText(getAddress(indoorSecurityCheckInfo));
    }

    /**
     * 故障等级：一级  红色   ； 二级  橙色   ； 正常  绿色
     * @param hiddenDangerLevel
     * @return
     */
    private int getStateTxtColor(String hiddenDangerLevel) {
        if ("1".equals(hiddenDangerLevel)) {
            return Color.parseColor("#D60000");
        } else if ("2".equals(hiddenDangerLevel)) {
            return Color.parseColor("#D66A00");
        }
        return Color.parseColor("#00D619");
    }

    private String getAddress(IndoorSecurityCheckListResp.IndoorSecurityCheckInfo indoorSecurityCheckInfo) {
        if(!TextUtils.isEmpty(indoorSecurityCheckInfo.addressList)) {
            return indoorSecurityCheckInfo.addressList.replace(",", "") + indoorSecurityCheckInfo.detailedAddress;
        } else {
            return "";
        }
    }

    /**
     * （隐患）故障等级
     //故障等级： 1 是一级  2是二级  0  正常
     //一级  红色   ； 二级  橙色   ； 正常  绿色
     * @param hiddenDangerLevel
     * @return
     */
    private String getBadLevelStr(String hiddenDangerLevel) {
        if ("1".equals(hiddenDangerLevel)) {
            return "一级";
        } else if ("2".equals(hiddenDangerLevel)) {
            return "二级";
        }
        return "正常";
    }
}
